package com.imooc.reader.management.controller;

import com.imooc.reader.management.dto.ResponseDTO;
import com.imooc.reader.management.entity.User;
import com.imooc.reader.management.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/authentication")
public class AuthenticationController {
    @Resource
    private UserService userService;
    @GetMapping("/info")
    public ResponseDTO selectUserByUsername() {
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        User user = (User)userService.loadUserByUsername(username);
        // 将敏感信息设置为null，不对外暴露
        user.setPassword(null);
        return new ResponseDTO().put("user", user);
    }
}
